package com.band.manager.util;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class generator {

    public static void generateMyDB() throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {
        List<String> warning = new ArrayList<>();
        boolean overwrite = true;
        InputStream is = generator.class.getResourceAsStream("/generatorConfig.xml");
        ConfigurationParser parser = new ConfigurationParser(warning);
        Configuration config = parser.parseConfiguration(is);
        is.close();

        DefaultShellCallback callback = new DefaultShellCallback(overwrite);

        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,callback,warning);

        myBatisGenerator.generate(null);

        for(String w:warning){
            System.out.println(w);
        }
    }
}
